home *** CD-ROM | disk | FTP | other *** search
- Subject: v14i078: Jove, an emacs variant, version 4.9, Part21/21
- Newsgroups: comp.sources.unix
- Sender: sources
- Approved: rsalz@uunet.UU.NET
-
- Submitted-by: Jonathan Payne <jpayne@cs.rochester.edu>
- Posting-number: Volume 14, Issue 78
- Archive-name: jove4.9/part21
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 21 (of 21)."
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f './mac.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'./mac.c'\"
- else
- echo shar: Extracting \"'./mac.c'\" \(48936 characters\)
- sed "s/^X//" >'./mac.c' <<'END_OF_FILE'
- X/***************************************************************************
- X * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne. JOVE *
- X * is provided to you without charge, and with no warranty. You may give *
- X * away copies of JOVE, including sources, provided that this notice is *
- X * included in all the files. *
- X ***************************************************************************/
- X
- X
- X/* (C) 1986, 1987, 1988 Ken Mitchum. This code is intended only for use with Jove. */
- X
- X#include "tune.h"
- X#ifdef MAC
- X#define _mac
- X#include <MacTypes.h>
- X#include "jove.h"
- X#include <QuickDraw.h>
- X#include <WindowMgr.h>
- X#include <FontMgr.h>
- X#include <ListMgr.h>
- X#include <EventMgr.h>
- X#include <ControlMgr.h>
- X#include <DialogMgr.h>
- X#include <ResourceMgr.h>
- X#include <ToolboxUtil.h>
- X#include <HFS.h>
- X#include <StdFilePkg.h>
- X#include <MenuMgr.h>
- X#include <pascal.h>
- X#include <errno.h>
- X#include <SegmentLdr.h>
- X#include "mac.h"
- X#include "termcap.h"
- X
- X/***************************************************/
- X
- X/* these normally reside in "tune.c" which we don't use */
- X
- char *CmdDb; /* see InitMac() */
- char *p_tempfile = ".jrecXXX";
- char *d_tempfile = ".joveXXX";
- char *Joverc = ".joverc";
- X
- X
- void putcurs(),curset(),putp(),dellines(),inslines();
- X
- X
- static WindowPtr theScreen;
- X
- int
- X errno,
- X EventCmd,
- X Keyonly,
- X Macmode,
- X Bufchange,
- X Modechange,
- X Windchange;
- X
- X
- X
- X
- X/* Initialization Routines. */
- X
- void InitBinds()
- X{
- X struct cmd *c;
- X data_obj **p;
- X int i;
- X
- X p = mainmap;
- X for(i= 0; i < NCHARS; i++) {
- X c = (struct cmd *) *p;
- X c->c_map = F_MAINMAP;
- X c->c_key = i;
- X p++;
- X }
- X
- X p = pref1map;
- X for(i= 0; i < NCHARS; i++) {
- X c = (struct cmd *) *p;
- X c->c_map = F_PREF1MAP;
- X c->c_key = i;
- X p++;
- X }
- X p = pref2map;
- X for(i= 0; i < NCHARS; i++) {
- X c = (struct cmd *) *p;
- X c->c_map = F_PREF2MAP;
- X c->c_key = i;
- X p++;
- X }
- X
- X}
- X
- static WindowPtr window;
- static Rect r;
- static CursHandle cross;
- X
- void InitEvents()
- X{
- X void InitSysMenu();
- X
- X window = theScreen;
- X InitSysMenu();
- X SetRect(&r,window->portRect.left,
- X window->portRect.top,
- X window->portRect.right - SCROLLWIDTH,
- X window->portRect.bottom - SCROLLWIDTH);
- X cross = GetCursor(crossCursor);
- X}
- X
- void MacInit()
- X{
- X char *gethome();
- X void tn_init();
- X
- X tn_init();
- X getdir();
- X gethome(); /* before anyone changes it */
- X CmdDb = malloc(strlen(gethome()) + 10);
- X strcpy(CmdDb,gethome());
- X strcat(CmdDb,"/cmds.doc");
- X InitBinds();
- X}
- X
- X
- X/* dummy routines. */
- X
- void InitCM()
- X{
- X}
- X
- void ResetTerm(){}
- X
- void UnsetTerm(s)
- char *s;
- X{
- X}
- X
- X
- X
- int dummy(){}
- X
- int (*signal(sig,func))()
- int sig;
- int (*func)();
- X{
- X return(&dummy);
- X}
- dorecover() {}
- X
- X
- X/* Surrogate unix-style file i/o routines for Jove. These replace the
- X routines distributed in the libraries. They work with Jove, but may
- X not be general enough for other purposes. */
- X
- X#include <io.h>
- X#define NFILES 10
- X/*
- X#define fsetup(p) {p.ioCompletion = 0; p.ioVRefNum = cur_vol; p.ioDirID = cur_dir;p.ioFVersNum = 0;}
- X#define isetup(p) {p.ioCompletion = 0; p.ioVRefNum = cur_vol;}
- X*/
- X
- static int cur_vol; /* Disk or volume number */
- static long cur_dir; /* Directory number */
- static int cur_vref; /* ugh.. Vref for volume + directory */
- X
- struct ftab {
- X int inuse; /* 0 = closed 1 = binary 2 = text*/
- X int refnum; /* Mac file reference number */
- X} ft[NFILES];
- X
- fsetup(p)
- HParmBlkPtr p;
- X{
- X bzero(p,sizeof(HParamBlockRec));
- X p->fileParam.ioVRefNum = cur_vol;
- X p->fileParam.ioDirID = cur_dir;
- X p->fileParam.ioFVersNum = 0;
- X}
- X
- isetup(p)
- HIOParam *p;
- X{
- X bzero(p,sizeof(HIOParam));
- X p->ioVRefNum = cur_vol;
- X}
- X
- X
- X/* Kludge to convert Macintosh error codes to something like Unix. */
- X
- static int cvt_err(err) /* some of these don't make sense... */
- X{
- X switch(err) {
- X case noErr: errno = 0; return(0);
- X case dirFulErr: errno = ENOSPC; break;
- X case dskFulErr: errno = ENOSPC; break;
- X case nsvErr: errno = ENOENT; break;
- X case ioErr: errno = EIO; break;
- X case bdNamErr: errno = EINVAL; break;
- X case fnOpnErr: errno = EBADF; break; /* dubious... */
- X case eofErr: errno = ESPIPE; break; /* ditto */
- X case posErr: errno = ESPIPE; break;
- X case mFulErr:
- X case tmfoErr:
- X case fnfErr: errno = ENOENT; break;
- X case wPrErr: errno = EROFS; break;
- X case fLckdErr: errno = EACCES; break;
- X case fBsyErr: errno = EBUSY; break;
- X case dupFNErr: errno = EEXIST; break;
- X case opWrErr:
- X case paramErr: errno = EINVAL; break;
- X case rfNumErr: errno = EBADF; break;
- X case gfpErr:
- X case volOffLinErr: errno = ENODEV; break;
- X case permErr: errno = EACCES; break;
- X case volOnLinErr: errno = ENODEV; break;
- X case nsDrvErr: errno = ENODEV; break;
- X case noMacDskErr: errno = EIO; break;
- X case extFSErr: errno = EIO; break;
- X case fsRnErr:
- X case badMDBErr:
- X case wrPermErr: errno = EPERM; break;
- X default: errno = ENOENT;
- X }
- X return(-1);
- X}
- X
- static char *cvt_fnm(file)
- char *file;
- X{
- X static char nm[255];
- X char *t;
- X
- X
- X if(*file == '/') strcpy(nm,file + 1); /* full path */
- X else {
- X if(index(file + 1, '/') != NULL)
- X strcpy(nm,"/"); /* make a partial pathname */
- X else *nm = '\0';
- X strcat(nm,file);
- X }
- X t = nm;
- X while(*t) {
- X if(*t == '/') *t = ':';
- X t++;
- X }
- X return(nm);
- X}
- X
- int creat(name,perm) /* permission mode is irrelevant on a Mac */
- char *name;
- X{
- X int fd, err;
- X char *nm;
- X HParamBlockRec p;
- X
- X nm = cvt_fnm(name); /* convert filename to Mac type name */
- X CtoPstr(nm);
- X for(fd = 0; fd < NFILES && ft[fd].inuse; fd++);
- X if(fd == NFILES) {
- X errno = EMFILE;
- X return(-1);
- X }
- X fsetup(&p); /* try to delete it, whether it is there or not. */
- X p.fileParam.ioNamePtr = (StringPtr) nm;
- X if((err = PBHDelete(&p,0)) != noErr && err != fnfErr) return(cvt_err(err));
- X if(do_creat(&p,nm) != 0) return(-1);
- X else {
- X ft[fd].inuse++;
- X ft[fd].refnum = p.ioParam.ioRefNum;
- X return(fd + 1);
- X }
- X}
- X
- int open(name,mode)
- char *name;
- X{
- X int fd, err;
- X char *nm;
- X HParamBlockRec p;
- X
- X nm = cvt_fnm(name); /* convert filename to Mac type name */
- X CtoPstr(nm);
- X for(fd = 0; fd < NFILES && ft[fd].inuse; fd++);
- X if(fd == NFILES) {
- X errno = EMFILE;
- X return(-1);
- X }
- X fsetup(&p);
- X if((mode & 3) == O_RDONLY) p.ioParam.ioPermssn = fsRdPerm;
- X if((mode & 3) == O_WRONLY) p.ioParam.ioPermssn = fsWrPerm;
- X if((mode & 3) == O_RDWR) p.ioParam.ioPermssn = fsRdWrPerm;
- X p.ioParam.ioNamePtr = (StringPtr) nm;
- X p.ioParam.ioMisc = 0;
- X if((err = PBHOpen(&p,0)) != noErr && err != fnfErr) return(cvt_err(err));
- X if(err == noErr && mode & O_CREAT && mode & O_EXCL) {
- X PBClose(&p,0);
- X errno = EEXIST;
- X return(-1);
- X }
- X if(err == fnfErr) {
- X if(mode & O_CREAT) {
- X if(do_creat(&p,nm) != 0) return(-1);
- X } else {
- X errno = ENOENT;
- X return(-1);
- X }
- X }
- X ft[fd].inuse++;
- X ft[fd].refnum = p.ioParam.ioRefNum;
- X if(mode & O_APPEND) p.ioParam.ioPosMode = fsFromLEOF;
- X else p.ioParam.ioPosMode = fsFromStart;
- X p.ioParam.ioPosOffset = 0;
- X if((err = PBSetFPos(&p,0)) != noErr) {
- X ft[fd].inuse = 0;
- X return(cvt_err(err));
- X }
- X errno = 0;
- X return(fd + 1);
- X}
- X
- static int do_creat(p,nm)
- HParmBlkPtr p;
- char *nm;
- X{
- X int err;
- X
- X fsetup(p);
- X p->fileParam.ioNamePtr = (StringPtr) nm;
- X if((err = PBHCreate(p,0)) != noErr) return(cvt_err(err));
- X fsetup(p);
- X p->fileParam.ioNamePtr = (StringPtr) nm;
- X p->fileParam.ioFDirIndex = 0;
- X if((err = PBHGetFInfo(p,0)) != noErr) return(cvt_err(err));
- X p->fileParam.ioDirID = cur_dir;
- X p->fileParam.ioFlFndrInfo.fdType = 'TEXT';
- X p->fileParam.ioFlFndrInfo.fdCreator = 'JV01';
- X p->fileParam.ioFlFndrInfo.fdFlags = 0;
- X p->fileParam.ioFVersNum = 0;
- X if((err = PBHSetFInfo(p,0)) != noErr) return(cvt_err(err));
- X fsetup(p);
- X p->ioParam.ioNamePtr = (StringPtr) nm;
- X p->ioParam.ioPermssn = fsRdWrPerm;
- X p->ioParam.ioMisc = 0;
- X if(cvt_err(PBHOpen(p,0))) return(-1);
- X return(0);
- X}
- X
- X
- int close(fd)
- X{
- X int err;
- X HParamBlockRec p;
- X
- X fsetup(&p);
- X p.ioParam.ioRefNum = ft[--fd].refnum;
- X ft[fd].inuse = 0;
- X/* if(cvt_err(PBFlushFile(&p,0)) < 0) return(-1);
- X fsetup(&p); */
- X if(cvt_err(PBClose(&p,0)) < 0) return(-1);
- X fsetup(&p);
- X p.ioParam.ioNamePtr = 0;
- X if(cvt_err(PBFlushVol(&p,0)) < 0) return(-1);
- X}
- X
- int read(fd,buf,n)
- char *buf;
- unsigned n;
- X{
- X int err;
- X IOParam p;
- X if(fd == 0) return(con_read(buf,n));
- X if(ft[--fd].inuse == 0) {
- X errno = EBADF;
- X return(-1);
- X }
- X isetup(&p);
- X p.ioRefNum = ft[fd].refnum;
- X p.ioBuffer = buf;
- X p.ioReqCount = n;
- X p.ioPosMode = fsFromMark;
- X p.ioPosOffset = 0;
- X if((err = PBRead(&p,0)) != noErr && err != eofErr) {
- X cvt_err(err);
- X return(-1);
- X }
- X while(n--) {
- X if(*buf == '\r') *buf = '\n'; /* convert from Mac style */
- X buf++;
- X }
- X errno = 0;
- X return(p.ioActCount);
- X}
- X
- int write(fd,buf,n)
- char *buf;
- unsigned n;
- X{
- X int err;
- X IOParam p;
- X char *obuf, *s;
- X
- X if(fd == 0) return(con_write(buf,n));
- X
- X s = obuf = malloc(n + 1);
- X if(obuf == 0) return(-1); /* shouldn't happen... */
- X if(ft[--fd].inuse == 0) {
- X errno = EBADF;
- X free(obuf);
- X return(-1);
- X }
- X isetup(&p);
- X p.ioRefNum = ft[fd].refnum;
- X p.ioBuffer = obuf;
- X p.ioReqCount = (long) n;
- X p.ioPosMode = fsFromMark;
- X p.ioPosOffset = 0L;
- X while(n--) {
- X if(*buf == '\n') *s = '\r'; /* make it look like Mac files */
- X else(*s = *buf);
- X buf++;
- X s++;
- X }
- X if((err = PBWrite(&p,0)) != noErr) {
- X free(obuf);
- X return(-1);
- X }
- X free(obuf);
- X return((int) p.ioActCount);
- X}
- X
- long lseek(fd,offset,type) /* The Mac version of this doesn't allocate new space. */
- long offset;
- unsigned type;
- X{
- X int err;
- X long cur_mark, eof, new_mark;
- X IOParam p;
- X
- X if(ft[--fd].inuse == 0) {
- X errno = EBADF;
- X return(-1);
- X }
- X
- X isetup(&p);
- X p.ioRefNum = ft[fd].refnum;
- X if((err = PBGetFPos(&p,0)) != noErr) {
- X cvt_err(err);
- X return(-1);
- X }
- X cur_mark = p.ioPosOffset;
- X isetup(&p);
- X p.ioRefNum = ft[fd].refnum;
- X if((err = PBGetEOF(&p,0)) != noErr) {
- X cvt_err(err);
- X return(-1);
- X }
- X eof = (long) p.ioMisc;
- X switch(type) {
- X case 0 :
- X new_mark = offset;
- X break;
- X case 1 :
- X new_mark = offset + cur_mark;
- X break;
- X case 2 :
- X new_mark = offset + eof;
- X }
- X if(new_mark > eof) { /* need more space in file */
- X isetup(&p);
- X p.ioRefNum = ft[fd].refnum;
- X p.ioMisc = (Ptr) new_mark;
- X if((err = PBSetEOF(&p,0)) != noErr) {
- X cvt_err(err);
- X return(-1);
- X }
- X/* if((err = PBAllocContig(&p,0)) != noErr) {
- X cvt_err(err);
- X return(-1);
- X }*/
- X }
- X isetup(&p);
- X p.ioRefNum = ft[fd].refnum;
- X p.ioPosOffset = new_mark;
- X p.ioPosMode = fsFromStart;
- X if((err = PBSetFPos(&p,0)) != noErr) {
- X cvt_err(err);
- X return(-1);
- X }
- X errno = 0;
- X return(p.ioPosOffset);
- X}
- X
- int unlink(name)
- char *name;
- X{ int fd, err;
- X char *nm;
- X HParamBlockRec p;
- X
- X nm = cvt_fnm(name); /* convert filename to Mac type name */
- X CtoPstr(nm);
- X fsetup(&p); /* try to delete it, whether it is there or not. */
- X p.fileParam.ioNamePtr = (StringPtr) nm;
- X if((err = PBHDelete(&p,0)) != noErr && err != fnfErr) return(cvt_err(err));
- X return;
- X}
- X
- X/* Console read and write routines */
- X
- static int con_write(buf,size)
- unsigned size;
- char *buf;
- X{
- X while(size--) putp(*buf++);
- X return(size);
- X}
- X
- static int con_read(buf,size)
- unsigned size;
- char *buf;
- X{
- X unsigned n;
- X int p;
- X
- X
- X n = 0;
- X do {
- X p = rawgetc();
- X#ifdef O_META
- X if(p & 0x7f) p &= 0x7f; /* was normal ascii char */
- X#endif
- X *buf++ = p;
- X n++;
- X } while (rawchkc() && n <= size);
- X return(n);
- X}
- X
- X
- X/* This didn't seem to be any place else */
- X
- int abs(n)
- int n;
- X{
- X return(n >= 0 ? n : -n);
- X
- X}
- X
- X/* Simplified stat() routine emulates what is needed most. */
- X
- int stat(fname,buf)
- char *fname;
- struct stat *buf;
- X{
- X CInfoPBRec p;
- X char *nm;
- X
- X nm = cvt_fnm(fname);
- X CtoPstr(nm);
- X bzero(&p,sizeof(CInfoPBRec));
- X p.hFileInfo.ioCompletion = 0;
- X p.hFileInfo.ioNamePtr = (StringPtr) nm;
- X p.hFileInfo.ioFVersNum = 0;
- X p.hFileInfo.ioFDirIndex = 0;
- X p.hFileInfo.ioVRefNum = cur_vol;
- X p.hFileInfo.ioDirID = cur_dir;
- X
- X switch (PBHGetFInfo(&p,0)) {
- X
- X case noErr : errno = 0;
- X break;
- X case nsvErr:
- X case paramErr:
- X case bdNamErr :
- X case fnfErr: errno = ENOENT;
- X break;
- X case ioErr: errno = EIO;
- X break;
- X default : errno = ENOENT;
- X break;
- X }
- X buf->st_dev = p.hFileInfo.ioVRefNum + 1; /* don't want 0 */
- X buf->st_ino = p.hFileInfo.ioDirID;
- X buf->st_size = p.hFileInfo.ioFlLgLen;
- X buf->st_mtime = p.hFileInfo.ioFlMdDat;
- X buf->st_mode = (p.hFileInfo.ioFlAttrib & 0x10) ? S_IFDIR : 0;
- X PtoCstr(nm);
- X return(errno == 0 ? 0 : -1);
- X}
- X
- X/* Directory related routines. Jove keeps track of the true Volume (disk) number and
- X directory number, and avoids "Working Directory Reference Numbers", which are
- X confusing. */
- X
- static int getdir() /* call this only once, during startup. */
- X{
- X WDPBRec p;
- X
- X p.ioCompletion = 0;
- X p.ioNamePtr = 0;
- X if(PBHGetVol(&p,0) != noErr) return(-1); /* BIG trouble */
- X cur_vol = p.ioWDVRefNum;
- X cur_dir = p.ioWDDirID;
- X SFSaveDisk = 0 - cur_vol; /* these are for SF dialogs */
- X CurDirStore = cur_dir;
- X}
- X
- static int setdir(vol,dir)
- long dir;
- X{
- X WDPBRec p;
- X
- X p.ioCompletion = 0;
- X p.ioNamePtr = 0;
- X p.ioVRefNum = vol;
- X p.ioWDDirID = dir;
- X if(PBHSetVol(&p,0) != noErr) return(-1);
- X cur_vol = vol;
- X cur_dir = dir;
- X SFSaveDisk = 0 - vol; /* these are for SF dialogs */
- X CurDirStore = dir;
- X
- X
- X}
- X
- int chdir(dir)
- char *dir;
- X{
- X DirInfo d;
- X WDPBRec p;
- X char *t;
- X char *nm;
- X
- X if(strcmp(dir,"/") == 0) return(-1); /* There is no root... */
- X nm = malloc(strlen(dir) + 2);
- X if(nm == 0) return(-1);
- X
- X strcpy(nm,dir);
- X t = nm;
- X while(*t) {
- X if(*t == '/') *t = ':';
- X t++;
- X }
- X t = nm;
- X while(*t == ':') t++; /*get rid of initial slashes */
- X strcat(nm,":");
- X CtoPstr(t);
- X
- X d.ioCompletion = 0; /* get the directory number */
- X d.ioNamePtr = (StringPtr) t;
- X d.ioVRefNum = cur_vol;
- X d.ioFDirIndex = 0;
- X d.ioDrDirID = 0;
- X PBGetCatInfo(&d,0);
- X free(nm);
- X if(d.ioResult != noErr || ((d.ioFlAttrib & 0x10) == 0)) return(-1);
- X if(setdir(d.ioVRefNum,d.ioDrDirID) < 0)return(-1);
- X return(0);
- X}
- X
- X/* Scandir returns the number of entries or -1 if the directory cannoot
- X be opened or malloc fails. */
- X
- int scandir(dir, nmptr, qualify, sorter) /* this function has NOT been debugged */
- char *dir;
- char ***nmptr;
- int (*qualify)();
- int (*sorter)();
- X{
- X HParamBlockRec fb;
- X DirInfo d;
- X long DirID;
- X char **ourarray, *nm, *t, buf[50];
- X Str255 buf1;
- X unsigned int len, nalloc = 10,
- X nentries = 0;
- X
- X if(strcmp(dir,"/") == 0) return(-1); /* There is no root... */
- X nm = malloc(strlen(dir) + 2);
- X if(nm == 0) return(-1);
- X
- X strcpy(nm,dir);
- X t = nm;
- X while(*t) {
- X if(*t == '/') *t = ':';
- X t++;
- X }
- X t = nm;
- X while(*t == ':') t++; /*get rid of initial slashes */
- X strcat(nm,":");
- X CtoPstr(t);
- X
- X d.ioCompletion = 0; /* get the directory number */
- X d.ioNamePtr = (StringPtr) t;
- X d.ioVRefNum = cur_vol;
- X d.ioFDirIndex = 0;
- X d.ioDrDirID = 0;
- X PBGetCatInfo(&d,0);
- X free(nm);
- X fb.fileParam.ioDirID = DirID = d.ioDrDirID;
- X fb.fileParam.ioCompletion = (long) 0;
- X fb.fileParam.ioVRefNum = cur_vol;
- X fb.fileParam.ioFVersNum = 0;
- X fb.fileParam.ioNamePtr = buf1;
- X
- X if ((ourarray = (char **) malloc(nalloc * sizeof (char *))) == 0)
- memfail: complain("[Malloc failed: cannot scandir]");
- X while (1) {
- X fb.fileParam.ioFDirIndex = nentries;
- X fb.fileParam.ioVRefNum = cur_vol;
- X fb.fileParam.ioDirID = DirID;
- X if(PBHGetFInfo(&fb,0) != noErr) break; /* we are done, then */
- X len = (char) *fb.fileParam.ioNamePtr; /* pascal style string */
- X strncpy(buf,fb.fileParam.ioNamePtr +1,len);
- X buf[len] = '\0';
- X
- X if (qualify != 0 && (*qualify)(buf) == 0)
- X continue;
- X if (nentries == nalloc) {
- X ourarray = (char **) realloc((char *) ourarray, (nalloc += 10) * sizeof (char *));
- X if (ourarray == 0)
- X goto memfail;
- X }
- X ourarray[nentries] = (char *) malloc(strlen(buf)+1);
- X null_ncpy(ourarray[nentries], buf, strlen(buf));
- X nentries += 1;
- X }
- X if ((nentries + 1) != nalloc)
- X ourarray = (char **) realloc((char *) ourarray,
- X ((nentries + 1) * sizeof (char *)));
- X if (sorter != 0)
- X qsort((char *) ourarray, nentries, sizeof (char **), sorter);
- X *nmptr = ourarray;
- X ourarray[nentries] = 0; /* guaranteed 0 pointer */
- X return nentries;
- X}
- X
- X
- char *getwd()
- X{
- X DirInfo d;
- X static char ret[255];
- X char nm[50], tmp[255];
- X
- X ret[0] = '\0';
- X d.ioDrDirID = cur_dir;
- X for(;;) {
- X d.ioCompletion = 0;
- X d.ioNamePtr = (StringPtr) nm;
- X d.ioVRefNum = cur_vol;
- X d.ioFDirIndex = -1;
- X
- X PBGetCatInfo(&d,0);
- X if(d.ioResult != noErr) return(0);
- X PtoCstr((char *) nm);
- X strcpy(tmp,ret);
- X strcpy(ret,"/");
- X strcat(ret,nm);
- X strcat(ret,tmp);
- X if(d.ioDrDirID == 2) break; /* home directory */
- X d.ioDrDirID = d.ioDrParID;
- X }
- X return(ret);
- X}
- X
- static char *gethome() /* this will be startup directory */
- X{
- X static char *ret = 0;
- X
- X
- X if(ret == 0) {
- X char *item = getwd();
- X ret = malloc(strlen(item)+1);
- X strcpy(ret,item);
- X }
- X return(ret);
- X}
- X
- X
- X
- X/* Routines that put up and manipulate the "About Jove" dialog. */
- X
- X
- X/* (ORIGINALLY IN) about_j.c. */
- X
- X
- X#define DLOGNAME "\pABOUT_JDLOG"
- X
- X#define DONE_ITEM 1
- X#define LIST_ITEM 2
- X
- X
- X#define DWIDTH 460 /* there should be an easy way to get this */
- X#define DHEIGHT 240 /* from the resource file! */
- X
- WindowPtr makedisplay();
- ListHandle makelist();
- X
- X
- static WindowPtr theWindow;
- static ListHandle theList;
- static Rect theListRect;
- static EventRecord theEvent;
- X
- X
- X
- static void about_j()
- X{
- X void do_list(), do_events();
- X
- X WindowPtr OldWindow;
- X
- X GetPort(&OldWindow);
- X
- X if((theWindow = makedisplay()) == 0) return;
- X SetPort(theWindow);
- X if(theList = makelist()) {
- X LActivate(1,theList);
- X do_list();
- X ShowWindow(theWindow);
- X do_events();
- X }
- X SetPort(OldWindow);
- X LDispose(theList);
- X DisposDialog(theWindow);
- X
- X return;
- X}
- X
- X
- static WindowPtr makedisplay()
- X{
- X static int dlogid = 0;
- X DialogPtr theDialog;
- X Handle theHandle;
- X Handle theResource;
- X Str255 buf;
- X long itemType;
- X Rect theRect;
- X short dh,dv; /* to center dialog on the screen */
- X Str255 nostring;
- X
- X if(dlogid == 0) {
- X if((theResource = GetNamedResource('DLOG',DLOGNAME)) == 0)
- X return((WindowPtr) 0);
- X itemType = 'DLOG';
- X GetResInfo(theResource,&dlogid,&itemType,buf);
- X }
- X
- X theDialog = GetNewDialog(dlogid,(long) 0,(WindowPtr) -1);
- X strcpy((char *) nostring,"\p");
- X ParamText("\pMacJove - Copyright (C) 1986, 1987, 1988 J. Payne, K. Gegenfurtner,",
- X "\pK. Mitchum. Portions (C) THINK Technologies, Inc.",nostring,nostring);
- X
- X dh = screenBits.bounds.left + (screenBits.bounds.right - DWIDTH) / 2;
- X dv = screenBits.bounds.top + (screenBits.bounds.bottom - DHEIGHT) / 2;
- X MoveWindow((WindowPtr)theDialog,dh,dv,0);
- X ShowWindow((WindowPtr)theDialog);
- X
- X
- X GetDItem(theDialog,LIST_ITEM,&itemType,&theHandle,&theRect);
- X theListRect = theRect;
- X theListRect.right -= 15;
- X ((WindowPtr)theDialog)->txFont = FONT;
- X ((WindowPtr)theDialog)->txSize = TEXTSIZE;
- X
- X return((WindowPtr) theDialog);
- X}
- X
- static void do_display() /* draw necessary controls, lines */
- X{
- X Rect rViewF; /* framing rect for list */
- X int offset;
- X
- X rViewF = theListRect;
- X
- X rViewF.left--;
- X rViewF.top--;
- X rViewF.right++;
- X rViewF.bottom++;
- X FrameRect(&rViewF);
- X
- X DrawControls(theWindow);
- X
- X}
- X
- static ListHandle makelist()
- X{
- X Point csize;
- X Rect dataBounds, rView; /* list boundaries */
- X
- X csize.h = csize.v = 0;
- X SetRect(&dataBounds,0,0,1,0);
- X return(LNew(&theListRect,&dataBounds,csize,0,theWindow,0,0,0,1));
- X}
- X
- static void do_list()
- X{
- X void printbind();
- X
- X int row, col;
- X struct cmd *f;
- X Str255 buf;
- X Point theCell;
- X
- X theCell.h = 0;
- X
- X for(f = commands, row = 0; f->Name; f++, row++) {
- X LAddRow(1,row,theList);
- X theCell.v = row;
- X
- X printbind(f,buf);
- X strcat(buf,f->Name);
- X LSetCell(buf,strlen((char *)buf),theCell,theList);
- X
- X }
- X}
- static void printbind(f,buf)
- struct cmd *f;
- char *buf;
- X{
- X char c;
- X
- X if(f->c_map == 0 || (c = f->c_key) == 0x7f) {
- X strcpy(buf," ");
- X return;
- X }
- X switch(f->c_map) {
- X case F_MAINMAP :
- X strcpy(buf," ");
- X break;
- X
- X case F_PREF1MAP :
- X strcpy(buf," ESC ");
- X break;
- X
- X case F_PREF2MAP :
- X strcpy(buf," ^X ");
- X break;
- X }
- X if(c < ' ') {
- X buf[5] = '^'; /* control char */
- X c |= 0x40;
- X }
- X else buf[5] = ' ';
- X if(c >= 'a' && c<= 'z') c &= 0x5f;
- X buf[6] = c;
- X buf[7] = ' ';
- X buf[8] = '\0';
- X}
- X
- X
- X
- static pascal Boolean ProcFilter(theDialog,event,itemHit)
- DialogPtr theDialog;
- EventRecord *event;
- int *itemHit;
- X{
- X theEvent = *event;
- X if(theEvent.what == keyDown && theEvent.message & charCodeMask == '\r') {
- X *itemHit = 1;
- X return(TRUE);
- X }
- X if(theEvent.what == activateEvt && (WindowPtr) theEvent.message == theWindow) {
- X LDoDraw(1,theList);
- X LActivate(1,theList);
- X }
- X if(theEvent.what == updateEvt && (WindowPtr) theEvent.message == theWindow) {
- X BeginUpdate(theWindow);
- X do_display();
- X DrawDialog(theWindow);
- X LUpdate((GrafPtr) theWindow->visRgn,theList);
- X EndUpdate(theWindow);
- X }
- X
- X return(FALSE);
- X}
- X
- X
- void do_events()
- X{
- X int item,done;
- X Point p;
- X
- X done = 0;
- X
- X while(!done) {
- X ModalDialog(ProcFilter,&item);
- X switch(item) {
- X case DONE_ITEM :
- X done = 1;
- X case LIST_ITEM :
- X p = theEvent.where;
- X GlobalToLocal(&p);
- X LClick(p,theEvent.modifiers,theList);
- X }
- X }
- X}
- X
- X/* Window and Control related routines. */
- X
- X/* (ORIGINALLY IN) tcon.c.
- X control handler routines for Jove. K. Mitchum 12/86 */
- X
- X
- X#define MINC 0
- X#define MAXC (int)100
- X#define INITC 0
- X#define EVENTLIST (mDownMask | keyDownMask )
- X
- extern long GetCRefCon(); /* omitted in ControlMgr.h */
- X
- static Point p;
- static intext; /* mouse down in jove text */
- X
- void docontrols() /* called from redisplay routines */
- X{
- X void MakeScrollBar(),
- X AdjustScrollBar(),
- X drawfluff();
- X
- X Window *w;
- X int top;
- X
- X w = fwind;
- X top = 0;
- X do {
- X if(w->w_control) HideControl(w->w_control);
- X w = w->w_next;
- X } while (w != fwind);
- X w = fwind;
- X do {
- X w->w_topline = top;
- X if(w->w_control) AdjustScrollBar(w);
- X else MakeScrollBar(w);
- X ShowControl(w->w_control);
- X top += w->w_height;
- X w = w->w_next;
- X } while(w != fwind);
- X Windchange = 0;
- X drawfluff();
- X}
- X
- X
- void MakeScrollBar(w) /* set up control */
- Window *w;
- X{
- X Rect BarRect;
- X int wheight, wtop;
- X
- X WindowPtr window = theScreen;
- X wheight = w->w_height;
- X wtop = w->w_topline;
- X SetRect(&BarRect,window->portRect.right - SCROLLWIDTH + 1,
- X window->portRect.top -1 + wtop * HEIGHT,
- X window->portRect.right +1,
- X window->portRect.top + ((wheight + wtop) * HEIGHT));
- X w->w_control = ((char **) NewControl(window,&BarRect,"/psbar",1,INITC,
- X MINC,MAXC,scrollBarProc,w));
- X}
- X
- void AdjustScrollBar(w) /* redo existing control */
- Window *w;
- X{
- X int wtop,wheight;
- X ControlHandle handle;
- X WindowPtr window;
- X
- X handle = (ControlHandle) w->w_control;
- X wtop = w->w_topline;
- X wheight = w->w_height;
- X window = (*handle)->contrlOwner;
- X
- X if(handle == 0) return;
- X
- X SizeControl(handle,SCROLLWIDTH,wheight * HEIGHT +1);
- X
- X MoveControl(handle,window->portRect.right - SCROLLWIDTH + 1,
- X window->portRect.top -1 + wtop * HEIGHT);
- X}
- X
- void SetScrollBar(handle) /* set value of the bar */
- ControlHandle handle;
- X{
- X
- X SetCtlValue(handle,ltoc());
- X}
- X
- X
- X
- static void dodivider() /* originally to divide windows, but not enough */
- X /* room in between lines, so just put line at bottom */
- X{
- X WindowPtr window;
- X PenState pnState;
- X
- X window = theScreen;
- X GetPenState(&pnState);
- X MoveTo(0,((MAXROW) * HEIGHT));
- X PenSize(1,1);
- X LineTo(window->portRect.right,(MAXROW) * HEIGHT);
- X SetPenState(&pnState);
- X return;
- X}
- X
- static void drawfluff() /* draw controls and dividers */
- X{
- X WindowPtr window;
- X Window *w = fwind;
- X
- X window = theScreen;
- X DrawControls(window);
- X
- X dodivider();
- X}
- X
- void RemoveScrollBar(w)
- Window *w;
- X{
- X if(w->w_control) DisposeControl(w->w_control);
- X dodivider(); /* erase the divider */
- X w->w_control = 0;
- X
- X}
- X
- static pascal void DScroll(control,part)
- ControlHandle control;
- int part;
- X{
- X DownScroll();
- X redisplay();
- X}
- X
- static pascal void UScroll(control,part)
- ControlHandle control;
- int part;
- X{
- X UpScroll();
- X redisplay();
- X}
- X
- static pascal void NPage(control,part)
- ControlHandle control;
- int part;
- X{ NextPage();
- X redisplay();
- X}
- X
- static pascal void PPage(control,part)
- ControlHandle control;
- int part;
- X{ PrevPage();
- X redisplay();
- X}
- X
- static long npos; /* number of lines in buffer */
- X
- static int ltoc() /* calculate ctlvalue for line position */
- X{
- X register long ipos;
- X register Line *lp = curbuf->b_first;
- X
- X for (npos = 1; lp ; npos++, lp = lp->l_next) {
- X if(lp == curline) ipos = npos;
- X }
- X return((int) ((ipos * MAXC) / npos));
- X}
- X
- static Line *ctol(ctlv) /* find buffer line for ctlvalue */
- int ctlv;
- X{
- extern char *itoa();
- X register long ipos;
- X register Line *lp = curbuf->b_first;
- X
- X ipos = (npos * ctlv)/MAXC;
- X while (ipos-- && lp->l_next) lp = lp->l_next;
- X return(lp);
- X}
- X
- static void doWind(event,window)
- EventRecord *event;
- WindowPtr window;
- X{
- X#define track() TrackControl(whichControl,p,(ProcPtr) 0)
- X
- X ControlHandle whichControl;
- X Window *jwind, *cwind;
- X int notcurwind;
- X int cpart; /* control part */
- X int oldval,newval,thumb = 0;
- X
- X p = event->where;
- X intext = 0;
- X notcurwind = 0;
- X GlobalToLocal(&p);
- X
- X if(event->what == mouseDown) {
- X if((cpart = FindControl(p,window,&whichControl)) == 0) return;
- X if((jwind = (Window *) (*whichControl)->contrlRfCon) != curwind) {
- X notcurwind++;
- X cwind = curwind;
- X SetWind(jwind);
- X }
- X switch (cpart) {
- X case inUpButton : TrackControl(whichControl,p,(ProcPtr) DScroll); break;
- X case inDownButton : TrackControl(whichControl,p,(ProcPtr) UScroll); break;
- X case inPageUp : TrackControl(whichControl,p,(ProcPtr) PPage); break;
- X case inPageDown : TrackControl(whichControl,p,(ProcPtr) NPage); break;
- X case inThumb : if(track()) {
- X newval = GetCtlValue(whichControl);
- X
- X if(newval == MAXC) Eof();
- X else if(newval == MINC) Bof();
- X else SetLine(ctol(newval));
- X }
- X break;
- X
- X }
- X if(notcurwind) {
- X SetWind(cwind);
- X redisplay();
- X }
- X redisplay(); /* again, to set the cursor */
- X }
- X else {
- X if(findtext()) redisplay();
- X }
- X}
- X
- X
- static void doGoAway(event,window)
- EventRecord *event;
- WindowPtr window;
- X{
- X if(TrackGoAway(window,&event->where) == TRUE) Leave();
- X}
- X
- static Window *rtowind(row) /* return jove window row is in */
- int row;
- X{
- X Window *w = fwind;
- X
- X do {
- X if((w->w_topline <= row) && ((w->w_height + w->w_topline) > row))
- X return(w);
- X w = w->w_next;
- X } while(w != fwind);
- X return(0);
- X}
- X
- static Line *windtol(w,row) /* return line for row in window */
- Window *w;
- int row;
- X{
- X Line *l = w->w_top;
- X
- X while(row--) if((l = l->l_next) == 0) return(0);
- X return(l);
- X}
- X
- X
- static int findtext() /* locate and move the point to match the mouse */
- X{
- X int row,col;
- X Window *w;
- X Line *l;
- X ptoxy(p,&row,&col);
- X if((w = rtowind(row)) == 0) return(0);
- X if(w != curwind) SetWind(w);
- X row -= w->w_topline; /* now have row number in window */
- X if(row >= w->w_height -1) return(0);
- X if((l = windtol(w,row)) == 0) return(0);
- X if(l->l_dline == 0) return(0);
- X this_cmd = LINECMD;
- X SetLine(l); /* Curline is in linebuf now */
- X if(w->w_flags & W_NUMLINES) col -= 8; /* adjust for line numbers */
- X if(col < 0) col = 0;
- X curchar = how_far(curline, col);
- X return(1);
- X}
- X
- X
- static int ptoxy(p,row,col) /* convert Point to terminal x,y coordinate */
- Point p;
- int *row,*col;
- X{
- X *row = (p.v / HEIGHT);
- X *col = (p.h / WIDTH );
- X if((*row > MAXROW) || (*col > MAXCOL)) return(ERROR);
- X return(0);
- X}
- X
- X/* Event-related routines. The Event loop is CheckEvents(), and is called whenever
- X a console read occurs or a call to charp(). During certain activities, such as ask(),
- X etc. non-keyboard events are ignored. This is set by the variable Keyonly.
- X As an update or activate event generates a call to redisplay(), it is important
- X that redisplay() and related routines NOT check for keyboard characters. */
- X
- X/* (ORIGINALLY IN) tevent.c
- X event handler for Jove. K Mitchum 12/86 */
- X
- X
- X#define SYS_ID 100
- X#define NOFUNC (void (*)()) 0
- X#define NEVENTS 16
- static int firsttime = 0;
- extern void doMouse(),dokeyDown(),doUpdate(),doActivate();
- static MenuHandle SysMenu;
- static void (*eventlist[])() =
- X{
- X NOFUNC, /* nullEvent */
- X doMouse,/* mouseDown */
- X doMouse, /* mouseUp */
- X dokeyDown, /* keyDown */
- X NOFUNC, /* keyUp */
- X dokeyDown, /* autoKey */
- X doUpdate, /* updateEvt */
- X NOFUNC, /* diskEvt */
- X doActivate, /* activateEvt */
- X NOFUNC, /* not used */
- X NOFUNC, /* networkEvt = 10 */
- X NOFUNC, /* driverEvt */
- X NOFUNC, /* app1Evt */
- X NOFUNC, /* app2Evt */
- X NOFUNC, /* app3Evt */
- X NOFUNC /* app4Ev */
- X};
- X
- X
- X
- static void CheckEvents()
- X{
- X#define Ticks (long *) 0x16A
- X
- X void SetBufMenu(),
- X MarkModes();
- X
- X static EventRecord theEvent;
- X static Point Mousep;
- X static long time = 0;
- X
- X
- X static void (*fptr)();
- X
- X
- X if(FrontWindow() == window) {
- X GetMouse(&Mousep);
- X if(PtInRect(Mousep,&r))
- X SetCursor(*cross);
- X else SetCursor(&arrow);
- X }
- X
- X SystemTask();
- X if(EventCmd && !Keyonly) return;
- X if(Bufchange != 0) SetBufMenu();
- X if(Modechange != 0) MarkModes();
- X while(GetNextEvent(everyEvent,&theEvent)) {
- X if ((theEvent.what < NEVENTS) && (fptr = eventlist[theEvent.what])) {
- X (*fptr)(&theEvent);
- X }
- X SystemTask();
- X }
- X if((*Ticks - time) > 3600) {
- X time = *Ticks;
- X UpdModLine = YES;
- X redisplay();
- X }
- X}
- X
- static void InitSysMenu()
- X{
- X void InitLocalMenus();
- X
- X SysMenu = NewMenu(SYS_ID,"\p\24");
- X AppendMenu(SysMenu,"\pAbout Jove");
- X AddResMenu(SysMenu,'DRVR');
- X InsertMenu(SysMenu,0);
- X InitLocalMenus();
- X DrawMenuBar();
- X}
- X
- extern void doWind(),doGoAway(),doSysMenu(),doSysClick();
- X#define NMEVENTS 7
- static void (*mouselist[])() =
- X{
- X NOFUNC, /* inDesk */
- X doSysMenu, /* inMenuBar */
- X doSysClick, /* inSysWindow */
- X doWind, /* inContent */
- X NOFUNC, /* inDrag */
- X NOFUNC, /* inGrow */
- X doGoAway /* inGoAwa */
- X};
- X
- X
- static void doMouse(event)
- EventRecord *event;
- X{
- X WindowPtr theWindow;
- X int wpart;
- X void (*fptr)();
- X
- X if(Keyonly) {
- X if(event->what == mouseDown) SysBeep(2);
- X return;
- X }
- X wpart = FindWindow(event->where,&theWindow);
- X if ((wpart < NMEVENTS) && (fptr = mouselist[wpart])) {
- X (*fptr)(event,theWindow);
- X }
- X
- X}
- X
- static void doSysMenu(event,window)
- EventRecord *event;
- WindowPtr window;
- X{
- X void ProcMenu();
- X
- X int Menu,Item;
- X long result = MenuSelect(event->where);
- X Menu = (result >> 16) & 0xffff;
- X Item = result & 0xffff;
- X if(Item == 0) return; /* no choice made */
- X
- X if(Menu == SYS_ID) { /* apple menu */
- X Str255 Name;
- X GrafPtr Port;
- X
- X if(Item == 1) about_j();
- X else {
- X GetItem(SysMenu,Item,Name);
- X GetPort(&Port);
- X OpenDeskAcc(Name);
- X SetPort(Port);
- X }
- X }
- X else ProcMenu(Menu,Item);
- X HiliteMenu(0);
- X EventCmd = 1;
- X
- X menus_on();
- X return;
- X
- X}
- X
- static void doSysClick(event,window)
- EventRecord *event;
- WindowPtr window;
- X{
- X SystemClick(event,window);
- X}
- X
- X
- X
- static void doUpdate(event)
- EventRecord *event;
- X{
- X WindowPtr theWindow, oldPort;
- X
- X theWindow = (WindowPtr) event->message;
- X
- X if(firsttime == 0) {
- X firsttime++;
- X BeginUpdate(theWindow);
- X EndUpdate(theWindow);
- X return;
- X }
- X
- X/* redisplay(); */
- X GetPort(&oldPort);
- X SetPort(theWindow);
- X BeginUpdate(theWindow);
- X if(theWindow == theScreen && Windchange == 0
- X && Keyonly == 0) {
- X Placur(0,0);
- X drawfluff();
- X cl_scr(1);
- X redisplay();
- X }
- X EndUpdate(theWindow);
- X
- X SetPort(oldPort);
- X}
- X
- static void doActivate(event)
- EventRecord *event;
- X{
- X WindowPtr theWindow;
- X ControlHandle control;
- X int hilite;
- X
- X theWindow = (WindowPtr) event->message;
- X SetPort(theWindow);
- X if(event->modifiers & activeFlag) {
- X hilite = 0;
- X }
- X else hilite = 255;
- X for(control = (ControlHandle) (((WindowPeek) theWindow)->controlList);
- X (control != 0); control = (*control)->nextControl) {
- X HiliteControl(control,hilite);
- X }
- X}
- X
- X/* Keyboard routines. The Option key was formerly used as a meta key.
- X However, to take advantage of the full (non-ASCII) character set,
- X this was removed. The corresponding code is ifdeffed O_META. */
- X
- X/* (ORIGINALLY IN) tkey.c
- X keyboard routines for Macintosh. K Mitchum 12/86 */
- X
- extern jmp_buf auxjmp;
- X
- static nchars = 0;
- static char charbuf[MCHARS];
- X/* the following kludges a meta key out of the option key by
- sending an escape sequence back to the dispatch routines. this is
- not elegant but it works, and doesn't alter escape sequences for
- those that prefer them. to remap the control or meta keys,
- see mackeys.h. */
- X
- static void dokeyDown(event)
- EventRecord *event;
- X{
- X unsigned mods;
- X register c;
- X static int cptr = 0;
- X
- X if(MCHARS - nchars < 2) return;
- X
- X c = (char)((event->message)&(charCodeMask));
- X
- X if(c == '`') c = '\033'; /* for those used to escapes */
- X
- X mods = event->modifiers;
- X
- X#ifdef O_META
- X if (mods & (optionKey | cmdKey)) {
- X#else
- X if (mods & (cmdKey)) {
- X#endif
- X if(mods & shiftKey)
- X c = sh_keycodes[(((event->message)&(keyCodeMask))>>8)];
- X else
- X c = nsh_keycodes[(((event->message)&(keyCodeMask))>>8)];
- X#ifdef O_META
- X if(mods & optionKey) { /* make escape sequence */
- X if(mods & cmdKey) c &= 0x1f;
- X charbuf[cptr++] = '\033';
- X cptr &= NMASK; /* zero if necessary */
- X nchars++;
- X }
- X else
- X#endif
- X { /* command key (control key) */
- X if((c == '2') || (c == '\\')) c = 0; /* so we have a null char */
- X if(c != '`') c &= 0x1f; /* make a control char */
- X }
- X }
- X charbuf[cptr++] = c;
- X cptr &= NMASK;
- X nchars++;
- X}
- X
- static int rawgetc()
- X{
- X static int cptr = 0;
- X register c;
- X
- X if(EventCmd) longjmp(auxjmp,0);
- X while(nchars <= 0) {
- X nchars = 0;
- X if(EventCmd) longjmp(auxjmp,0);
- X CheckEvents(); /* ugh! WAIT for a character */
- X }
- X nchars--;
- X c = charbuf[cptr++];
- X cptr &= NMASK; /* zero if necessary */
- X return(c);
- X}
- X
- int rawchkc()
- X{
- X if(EventCmd) longjmp(auxjmp,0);
- X if(nchars == 0) CheckEvents(); /* this should NOT be necessary! */
- X return(nchars > 0);
- X}
- X
- X/* Routines for calling the standard file dialogs, when macify is ON. If the user
- X changes the directory using the file dialogs, Jove's notion of the current directory
- X is updated. */
- X
- X
- X/* (ORIGINALLY IN) tmacf.c. K. Mitchum 12/86.
- X Macify routines for jove. */
- X
- int CurrentVol; /* see tfile.c */
- X
- X
- X#define TYPES -1
- X
- static Point px = {100,100};
- static char pmess[] = "\pSave file as: ";
- X
- static pascal Boolean Ffilter(p)
- FileParam *p;
- X{
- X if(p->ioFlFndrInfo.fdType == 'APPL') return TRUE;
- X PtoCstr((char *) p->ioNamePtr);
- X if(strcmp(p->ioNamePtr,d_tempfile) == 0) {
- X CtoPstr((char *) p->ioNamePtr);
- X return TRUE;
- X }
- X CtoPstr((char *) p->ioNamePtr);
- X return FALSE;
- X}
- X
- static void check_dir()
- X{
- X if(cur_vol != 0 - SFSaveDisk || cur_dir != CurDirStore) {
- X setdir(0 - SFSaveDisk, CurDirStore);
- X UpdModLine = YES; /* make sure jove knows the change */
- X Modechange++;
- X setCWD(getwd());
- X }
- X}
- X
- char *gfile(namebuf) /* return a filename to get */
- char *namebuf;
- X{
- X SFReply frec;
- X char ans[FILESIZE];
- X
- X SFSaveDisk = 0 - cur_vol; /* in case a Desk Accessory changed them */
- X CurDirStore = cur_dir;
- X SFGetFile(px,0L,Ffilter,TYPES,0L,0L,&frec);
- X check_dir(); /* see if any change, set if so */
- X if(frec.good) {
- X EventRecord theEvent;
- X while(GetNextEvent(updateMask,&theEvent) == 0);
- X doUpdate(&theEvent);
- X PtoCstr((char *)frec.fName);
- X strcpy(ans,frec.fName);
- X CtoPstr((char *)frec.fName);
- X PathParse(ans,namebuf);
- X return(namebuf);
- X }
- X return(char *) 0;
- X}
- X
- char *pfile(namebuf)
- char *namebuf;
- X{
- X SFReply frec;
- X char *t, *nm;
- X SFSaveDisk = 0 - cur_vol; /* in case a Desk Accessory changed them */
- X CurDirStore = cur_dir;
- X strncpy(namebuf,filename(curbuf),63);
- X nm = cvt_fnm(namebuf);
- X CtoPstr(nm);
- X SFPutFile(px,pmess,nm,0L,&frec);
- X check_dir(); /* see if any change, set if so */
- X if(frec.good) {
- X EventRecord theEvent;
- X while(GetNextEvent(updateMask,&theEvent) == 0);
- X doUpdate(&theEvent);
- X t = (char *)frec.fName;
- X PtoCstr((char *)frec.fName);
- X while(*t == ':') t++; /* convert to unix style */
- X nm = t;
- X while(*nm) {
- X if(*nm == ':') *nm = '/';
- X nm++;
- X }
- X PathParse(t,namebuf);
- X return(namebuf);
- X }
- X return(char *) 0;
- X}
- X
- X
- X/* getArgs() returns an argument list based on documents clicked on by the user. */
- X
- int getArgs(avp)
- char ***avp;
- X{
- X int argc, nargs, type, old_vol;
- X long old_dir;
- X char **argv;
- X char *pathname;
- X AppFile p;
- X WDPBRec d;
- X
- X old_vol = cur_vol;
- X old_dir = cur_dir;
- X
- X CountAppFiles(&type,&nargs);
- X if(nargs > 0) { /* files to open... */
- X argv = (char **) malloc((nargs + 2) * sizeof(char *));
- X for(argc = 1; argc <= nargs; argc++) {
- X GetAppFiles(argc,&p);
- X if(type == 0) {
- X PtoCstr((char *)p.fName);
- X d.ioCompletion = 0;
- X d.ioNamePtr = 0;
- X d.ioVRefNum = p.vRefNum;
- X d.ioWDIndex = 0;
- X PBGetWDInfo(&d,0);
- X cur_vol = d.ioWDVRefNum;
- X cur_dir = d.ioWDDirID;
- X pathname = getwd();
- X argv[argc] = malloc(strlen((char *)p.fName) + strlen(pathname) + 2);
- X strcpy(argv[argc],pathname);
- X strcat(argv[argc],"/");
- X strcat(argv[argc],(char *)p.fName);
- X }
- X ClrAppFiles(argc);
- X }
- X if(type != 0) argc = 1;
- X }
- X else {
- X argv = (char **) malloc(2 * sizeof(char*));
- X argc = 1;
- X }
- X argv[0] = "jove";
- X
- X argv[argc] = 0;
- X *avp = argv;
- X cur_dir = old_dir;
- X cur_vol = old_vol;
- X return(argc);
- X}
- X
- X/* Limited version of getenv() */
- X
- char *getenv(item)
- char *item;
- X{
- X char *ret = 0, *str = 0;
- X
- X if(strcmp(item,"CWD") == 0) str = getwd();
- X if(strcmp(item,"HOME") == 0) str = gethome();
- X if(str) {
- X ret = malloc(strlen(str) + 1);
- X strcpy(ret,str);
- X }
- X return(ret);
- X}
- X
- char *mktemp(name)
- char *name;
- X{
- X return name;
- X}
- X
- X
- X/* Menu routines. The menus items are set up in a similar manner as keys, and
- X are bound prior to runtime. See menumaps.txt, which must be run through setmaps.
- X Unlike keys, menu items may be bound to variables, and to buffers. Buffer binding
- X is only done at runtime. */
- X
- static void InitLocalMenus()
- X{
- X void InitMenu(),
- X make_edits();
- X
- X int i;
- X for(i = 0; i < NMENUS; i++) {
- X InitMenu(&Menus[i]);
- X if(i == 0) make_edits(Menus[i].menu_id + 1);
- X }
- X}
- X
- static void InitMenu(M)
- struct menu *M;
- X{
- X int i;
- X data_obj *d;
- X char *name;
- X
- X if(M->menu_id == 0) return;
- X M->Mn = NewMenu(M->menu_id,CtoPstr(M->Name));
- X PtoCstr(M->Name);
- X
- X for(i = 0; i < NMENUITEMS; i++) {
- X d = (M->m[i]);
- X if(d == 0) break; /* last item... */
- X switch (d->Type & TYPEMASK) {
- X case (STRING) :
- X AppendMenu(M->Mn,CtoPstr(d->Name));
- X PtoCstr(d->Name);
- X break;
- X case (VARIABLE) :
- X SetItemMark(M->Mn,i + 1, 0x12);
- X case (FUNCTION) :
- X CtoPstr(name = ((data_obj *) d)->Name);
- X AppendMenu(M->Mn,name);
- X PtoCstr(name);
- X }
- X }
- X InsertMenu(M->Mn,0);
- X}
- X
- static void ProcMenu(menuno,itemno)
- int menuno,itemno;
- X{
- X void MacSetVar();
- X
- X int i;
- X data_obj *d;
- X
- X for(i = 0; i < NMENUS && Menus[i].menu_id != menuno; i++);
- X if(i < NMENUS) { /* found the menu */
- X itemno--;
- X d = Menus[i].m[itemno];
- X switch(d->Type & TYPEMASK) {
- X case FUNCTION :
- X ExecCmd((data_obj *) d);
- X break;
- X case BUFFER :
- X SetABuf(curbuf);
- X tiewind(curwind,(Buffer *) d);
- X SetBuf((Buffer *) d);
- X break;
- X case VARIABLE :
- X MacSetVar((struct variable *) d,i,itemno);
- X break;
- X default :
- X break;
- X }
- X
- X }
- X}
- X
- X
- X
- X
- X
- X
- static void make_edits(menu) /* add dummy edit menu */
- int menu;
- X{
- X MenuHandle M;
- X int item;
- X char *fname;
- X
- X M = NewMenu((menu),"\pEdit");
- X AppendMenu(M,"\pUndo/Z;(-;Cut/X;Copy/C;Paste/V;Clear;Select All;(-;Show Clipboard");
- X InsertMenu(M,0);
- X DisableItem(M,0);
- X}
- X
- void menus_off()
- X{
- X int i;
- X
- X if(Keyonly || EventCmd) return;
- X DisableItem(SysMenu,0);
- X for(i = 0; i < NMENUS; i++)
- X if(Menus[i].Mn) DisableItem(Menus[i].Mn,0);
- X Keyonly = 1;
- X DrawMenuBar();
- X}
- X
- void menus_on()
- X{
- X int i;
- X
- X if(Keyonly == 0) return;
- X EnableItem(SysMenu,0);
- X for(i = 0; i < NMENUS; i++)
- X if(Menus[i].Mn) EnableItem(Menus[i].Mn,0);
- X Keyonly = 0;
- X DrawMenuBar();
- X}
- X
- static char *BufMPrint(b,i)
- Buffer *b;
- X{
- X char *p;
- X char *nm = filename(b);
- X char t[35];
- X
- X if(strlen(nm) > 30) {
- X strcpy(t,"...");
- X strcat(t,nm + strlen(nm) - 30);
- X }
- X else strcpy(t,nm);
- X nm = t;
- X while(*nm) {
- X switch(*nm) { /* ugh... these are metacharacter for Menus */
- X case '/' : *nm = ':'; break;
- X case '^' :
- X case '!' :
- X case '<' :
- X case '(' :
- X case ';' : *nm = '.'; break; /* that will confuse everybody */
- X }
- X nm++;
- X }
- X p = sprint("%-2d %-11s \"%-s\"",i,b->b_name,t);
- X return(p);
- X}
- X
- static void SetBufMenu()
- X{
- X register Buffer *b;
- X data_obj *d;
- X int i,j,stop;
- X struct menu *M;
- X
- X Bufchange = 0;
- X for(i = 0; i < NMENUS && strcmp(Menus[i].Name,"Buffer"); i++);
- X if(i < NMENUS) {
- X M = &Menus[i];
- X for(j = 0; j < NMENUITEMS && (d = Menus[i].m[j]) && (d->Type & TYPEMASK) != BUFFER; j++);
- X if(j < NMENUITEMS) {
- X for(i = j, b = world; i < NMENUITEMS && b != 0; i++, b = b->b_next) {
- X
- X if(M->m[i] == 0)
- X AppendMenu(M->Mn,CtoPstr(BufMPrint(b,i-j+1))); /* add the item */
- X else
- X SetItem(M->Mn,i + 1,CtoPstr(BufMPrint(b,i-j+1))); /* or change it */
- X M->m[i] = (data_obj *) b;
- X }
- X stop = i;
- X /* out of buffers? */
- X for(;i < NMENUITEMS && M->m[i];i++) {
- X DelMenuItem(M->Mn,stop + 1); /* take off last item */
- X M->m[i] = 0;
- X }
- X }
- X }
- X return;
- X}
- X
- static void MacSetVar(vp,mnu,itm) /* Set a variable from the menu */
- struct variable *vp; /* Liberally taken from SetVar() in extend.c */
- int mnu,itm;
- X{
- X void MarkVar();
- X
- X char *prompt;
- X
- X prompt = sprint("Set %s: ", vp->Name);
- X switch (vp->v_flags & V_TYPEMASK) {
- X case V_BASE10:
- X case V_BASE8:
- X {
- X int value;
- X
- X value = ask_int(prompt, ((vp->v_flags & V_TYPEMASK) == V_BASE10)
- X ? 10 : 8);
- X *(vp->v_value) = value;
- X break;
- X }
- X case V_BOOL: /* toggle the value */
- X *(vp->v_value) = (*vp->v_value == ON ? OFF : ON);
- X MarkVar(vp,mnu,itm);
- X break;
- X case V_FILENAME:
- X case V_STRING:
- X {
- X char *str;
- X
- X /* Do_ask() so you can set string to "" if you so desire. */
- X str = do_ask("\r\n", (int (*)()) 0, (char *) vp->v_value, prompt);
- X if (str == 0)
- X str = NullStr;
- X strcpy((char *) vp->v_value, str);
- X /* ... and hope there is enough room. */
- X break;
- X }
- X case V_CHAR:
- X f_mess(prompt);
- X *(vp->v_value) = addgetc();
- X break;
- X }
- X
- X if (vp->v_flags & V_MODELINE)
- X UpdModLine = YES;
- X if (vp->v_flags & V_CLRSCREEN) ClAndRedraw();
- X if (vp->v_flags & V_TTY_RESET) tty_reset(); /* probably none on a Mac */
- X return;
- X}
- X
- static void MarkModes()
- X{
- X int mnu,itm,checked;
- X data_obj *d;
- X
- X Modechange = 0;
- X for(mnu = 0; mnu < NMENUS; mnu++)
- X for(itm = 0; itm < NMENUITEMS; itm++) {
- X if((d = Menus[mnu].m[itm]) == 0) break;
- X if((d->Type & (MAJOR_MODE | MINOR_MODE)) ||
- X ((d->Type & TYPEMASK) == BUFFER)){
- X if(d->Type & (MAJOR_MODE))
- X checked = (curbuf->b_major == (d->Type >> 8)) ? 1 : 0;
- X else if(d->Type & (MINOR_MODE))
- X checked = (curbuf->b_minor & (d->Type >> 8)) ? 1 : 0;
- X else
- X checked = (d == (data_obj *) curbuf) ? 1 : 0;
- X CheckItem(Menus[mnu].Mn, itm + 1, checked);
- X }
- X }
- X}
- X
- void MarkVar(vp,mnu,itm) /* mark a boolean menu item */
- struct variable *vp;
- int mnu,itm;
- X{
- X int checked;
- X if(mnu == -1) { /* we don't know the item... slow */
- X int found;
- X for(mnu = 0, found = 0; (mnu < NMENUS) && !found; mnu++) {
- X for(itm = 0; (itm < NMENUITEMS); itm++)
- X if((struct variable *) (Menus[mnu].m[itm]) == vp) {
- X found++;
- X break;
- X }
- X if(found) break;
- X }
- X if(!found) return;
- X }
- X checked = (*(vp->v_value) == ON);
- X CheckItem(Menus[mnu].Mn, itm + 1, checked);
- X}
- X
- static void MarkAllVar() /* slow, but only do it once */
- X{
- X int mnu,itm;
- X data_obj *d;
- X for(mnu = 0; mnu < NMENUS; mnu++)
- X for(itm = 0; itm < NMENUITEMS; itm++) {
- X if((d = Menus[mnu].m[itm]) == 0) break;
- X if((d->Type & TYPEMASK) == VARIABLE)
- X MarkVar((struct variable *)Menus[mnu].m[itm],mnu,itm);
- X }
- X}
- X
- X
- X/* Screen routines and driver. The Macinitosh Text Edit routines are not utilized,
- X as they are slow and cumbersome for a terminal emulator. Instead, direct QuickDraw
- X calls are used. The fastest output is obtained writing a line at a time, rather
- X than on a character basis, so the major output routine is writechr(), which takes
- X a pascal-style string as an argument. See bufputc() in screen.c. */
- X
- void Placur(line,col)
- int line, col;
- X{
- X CapCol = col;
- X CapLine = line;
- X putcurs(line,col,ON);
- X}
- X
- void NPlacur(line,col)
- int line, col;
- X{
- X CapCol = col;
- X CapLine = line;
- X putcurs(line,col,OFF);
- X}
- X
- void i_lines(top, bottom, num)
- int top, bottom, num;
- X{
- X Placur(bottom - num + 1, 0);
- X dellines(num,bottom);
- X Placur(top, 0);
- X inslines(num,bottom);
- X}
- X
- void d_lines(top, bottom, num)
- int top, bottom, num;
- X{
- X Placur(top, 0);
- X dellines(num,bottom);
- X Placur(bottom + 1 - num, 0);
- X inslines(num,bottom);
- X}
- X
- X
- void clr_page()
- X{
- X void wipescreen();
- X
- X wipescreen();
- X}
- X
- void clr_eoln()
- X{
- X void wipeline();
- X
- X wipeline();
- X}
- X
- void SO_on()
- X{
- X void HLmode();
- X
- X HLmode(1);
- X}
- X
- void SO_off()
- X{
- X void HLmode();
- X
- X HLmode(0);
- X}
- X
- X
- X/* (ORIGINALLY IN) tn.c */
- X/* window driver for MacIntosh using windows. */
- X/* K. Mitchum 9/86 */
- X
- X
- X
- X/*#define VARFONT*/
- X#ifdef VARFONT
- static height,width,theight,twidth,descent;
- X#else
- X#define height HEIGHT
- X#define width WIDTH
- X#define theight THEIGHT
- X#define twidth TWIDTH
- X#define descent DESCENT
- X#endif
- X
- static trow,tcol, insert, tattr, cursor;
- static Rect cursor_rect;
- X
- X
- static Rect vRect;
- static WindowRecord myWindowRec;
- static Rect myBoundsRect;
- X
- X
- X#define active() SetPort(theScreen)
- X/*#define active()*/
- X#define maxadjust(r) OffsetRect(r,0,2);
- static void tn_init()
- X{
- X void INSmode(),
- X init_slate();
- X
- X HLmode(0);
- X INSmode(0);
- X init_slate();
- X ShowPen();
- X}
- X
- static void wipescreen() /* clear and home function */
- X{
- X Rect r;
- X
- X active();
- X SetRect(&r, 0,0,WINDWIDTH,WINDHEIGHT);
- X EraseRect(&r);
- X cursor = OFF;
- X putcurs(0,0);
- X drawfluff();
- X}
- X
- static void putcurs(row,col,vis)
- unsigned row, col, vis;
- X{
- X/* if(row > MAXROW || col > MAXCOL) return(ERROR);*/
- X/* if(row != trow || col != tcol) */{
- X active();
- X curset(OFF);
- X if(row == MAXROW)
- X MoveTo(col * width, (row +1) * height + 2 -descent );
- X else
- X MoveTo(col * width, (row +1) * height - descent);
- X trow = row;
- X tcol = col;
- X curset(vis);
- X }
- X}
- X
- static void curset(desired)
- X{
- X if(cursor != desired) {
- X SetRect(&cursor_rect, tcol * width, (trow) * height , (tcol + 1) * width - 1, (trow +1) * height -1);
- X if(trow == MAXROW) maxadjust(&cursor_rect);
- X InvertRect(&cursor_rect);
- X cursor = desired;
- X }
- X}
- X
- X
- void putp(p) /* put one character, advance cursor */
- int p;
- X{
- X static Rect r;
- X static RgnHandle updateRgn;
- X
- X active();
- X curset(OFF);
- X if(insert) {
- X updateRgn = NewRgn();
- X SetRect(&r, tcol * width, trow * height, WINDWIDTH, (trow +1) * height -1);
- X if(trow == MAXROW) maxadjust(&r);
- X ScrollRect(&r, width, 0, updateRgn);
- X DisposeRgn(updateRgn);
- X }
- X if(p == '0') p = 0xAF; /* slashed zero */
- X DrawChar(p);
- X if(tcol >= MAXCOL) putcurs(trow,MAXCOL);
- X else putcurs(trow,tcol +1);
- X}
- X
- static void wipeline()
- X{
- X static Rect r;
- X
- X active();
- X cursor = OFF;
- X SetRect(&r, tcol * width, trow * height, WINDWIDTH, (trow +1) * height);
- X if(trow == MAXROW) maxadjust(&r);
- X EraseRect(&r);
- X curset(ON);
- X}
- X
- static void delchars()
- X{
- X static Rect r;
- X static RgnHandle updateRgn;
- X
- X active();
- X curset(OFF);
- X updateRgn = NewRgn();
- X SetRect(&r, tcol * width, trow * height, twidth - width, (trow +1) * height);
- X if(trow == MAXROW) maxadjust(&r);
- X ScrollRect(&r, 0 - width, 0, updateRgn);
- X DisposeRgn(updateRgn);
- X curset(ON);
- X}
- X
- static void dellines(n,bot)
- int n,bot;
- X{
- X Rect r;
- X RgnHandle updateRgn;
- X
- X updateRgn = NewRgn();
- X active();
- X curset(OFF);
- X SetRect(&r, 0, ((trow) * height), WINDWIDTH, ((bot + 1) * height));
- X ScrollRect(&r, 0, 0 - (n * height), updateRgn);
- X DisposeRgn(updateRgn);
- X putcurs(trow,0);
- X
- X}
- X
- static void inslines(n,bot)
- int n,bot;
- X{
- X Rect r;
- X RgnHandle updateRgn;
- X
- X updateRgn = NewRgn();
- X active();
- X curset(OFF);
- X SetRect(&r, 0, trow * height, WINDWIDTH, (bot +1) * height);
- X ScrollRect(&r, 0, (n * height), updateRgn);
- X DisposeRgn(updateRgn);
- X putcurs(trow,0);
- X}
- X
- static void INSmode(new)
- int new;
- X{
- X insert = new;
- X}
- X
- static void HLmode(new)
- int new;
- X{
- X if(new) tattr = 1;
- X else tattr = 0;
- X}
- X
- void writechr(start)
- char *start; /* actually, a Str255 type string */
- X{
- X static Rect r;
- X static RgnHandle updateRgn;
- X register len;
- X register char save;
- X
- X len = (int) start[0]; /* adjusted 6/86 K. M. in td.c*/
- X
- X active();
- X curset(OFF);
- X if(insert) {
- X updateRgn = NewRgn();
- X SetRect(&r, tcol * width, trow * height, twidth - width * len, (trow +1) * height -1);
- X if(trow == MAXROW) maxadjust(&r);
- X ScrollRect(&r, width * len, 0, updateRgn);
- X DisposeRgn(updateRgn);
- X }
- X DrawString(start);
- X
- X if(tcol >= MAXCOL) putcurs(trow,MAXCOL);
- X else putcurs(trow,tcol +len);
- X}
- X
- X
- X
- static void reset(){}
- static void blanks(){}
- static void cleanup() {}
- X
- X
- static void init_slate()
- X{
- X FontInfo f;
- X
- X extern char *version;
- X char *Name = "MacJove ";
- X char *Title;
- X
- X InitGraf(&thePort);
- X InitWindows();
- X InitCursor();
- X InitFonts ();
- X InitMenus ();
- X InitDialogs ((ProcPtr) 0); /* no restart proc */
- X
- X tn_left = screenBits.bounds.left + 3;
- X tn_top = screenBits.bounds.top + 40;
- X
- X tn_rows = (screenBits.bounds.bottom - 3 - tn_top) / HEIGHT;
- X tn_cols = (screenBits.bounds.right - 3 - tn_left - SCROLLWIDTH) / WIDTH;
- X tn_right = tn_left + tn_cols * WIDTH + SCROLLWIDTH;
- X tn_bottom = tn_top + tn_rows * HEIGHT + 2;
- X tn_cols++; /* kludge to get jove to use last col */
- X
- X LI = tn_rows;
- X CO = tn_cols;
- X MAXROW = tn_rows -1;
- X MAXCOL = tn_cols -1;
- X
- X SetRect(&myBoundsRect,tn_left,tn_top,tn_right,tn_bottom);
- X
- X Title = sprint("%s%s",Name,version);
- X theScreen = NewWindow(&myWindowRec, &myBoundsRect,CtoPstr(Title),
- X 1,noGrowDocProc,(WindowPtr) -1, 1, (long) 0);
- X
- X
- X
- X SetPort(theScreen);
- X
- X/* SetOrigin(-3,-1);*/
- X (theScreen)->txFont = FONT;
- X (theScreen)->txSize = TEXTSIZE;
- X
- X#ifdef VARFONT
- X GetFontInfo(&f);
- X height = f.ascent+f.descent+f.leading;
- X width = f.widMax;
- X twidth = width * tn_cols;
- X theight = height * tn_rows;
- X descent = f.descent;
- X#endif
- X
- X/* (theScreen)->lineHeight = height;
- X (theScreen)->fontAscent = ASCENT;*/
- X theScreen->txMode = patCopy;
- X theScreen->pnMode = patCopy;
- X PenNormal();
- X cursor = OFF;
- X}
- X#endif /* MAC */
- X
- X
- END_OF_FILE
- if test 48936 -ne `wc -c <'./mac.c'`; then
- echo shar: \"'./mac.c'\" unpacked with wrong size!
- fi
- # end of './mac.c'
- fi
- echo shar: End of archive 21 \(of 21\).
- cp /dev/null ark21isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 21 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-